// pages/index/allHot/allHot.js
import config from "../../../utils/config.js";
Page({
  /**
   * Page initial data
   */
  data: {
    topImgUrl: "",//top img
    allHotList: [],//hot goods list
    currentList: [],//show it
    step: 6,
    isActive: 0
  },

  //change card
  changeCard: function(e) {
    // console.log(e.currentTarget.dataset.i);
    var end = e.currentTarget.dataset.i * this.data.step + this.data.step;
    var temp = [];
    for (var i = e.currentTarget.dataset.i*this.data.step;i<end;i++) {
      temp.push(this.data.allHotList[i]);
    }
    this.setData({
      step: this.data.allHotList.length / 4,
      isActive: e.currentTarget.dataset.i,
      currentList: temp
    });
    // console.log(this.data.currentList);
  },
  //show more
  showMore: function() {
    this.setData({
      currentList: this.data.currentList.concat(this.data.allHotList)
    })
  },
  //back to top
  goTop: function() {
    wx.pageScrollTo({
      scrollTop: 0,
    })
  },
  // show goods details
  showGoodsDetails(e) {
    // console.log(e.currentTarget.dataset.gid);
    wx.navigateTo({
      url: '../../logs/details/details?id=' + e.currentTarget.dataset.gid,
    });
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function (options) {
    var that = this;
    wx.setNavigationBarTitle({
      title: '全部热租',
    });
    wx.request({//get hot list
      url: config.list,
      method: "get",
      data: {isHot: 1,page: 1,size: 30},
      success: function(res) {
        // console.log(res.data.data);
        var temp = [];
        that.setData({
          topImgUrl: res.data.data.goodsList[0].list_pic_url,
          allHotList: res.data.data.goodsList,
        });
        for (var i = 0; i < that.data.step; i++) {
          temp.push(that.data.allHotList[i]);
        }
        that.setData({
          currentList: temp
        })
      }
    });
    
  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function () {
  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function () {

  },

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function () {

  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function () {

  },

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function () {

  },

  /**
   * Called when page reach bottom
   */
  onReachBottom: function () {

  },

  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage: function () {

  }
})